<template>
	<view class="container">
		<view class="contenter">
			<text>{{$t('zhujici.zhujici1')}}</text>
		</view>

		<view class="content">
			<view class="content-title">
				<text>{{$t('zhujici.zhujici2')}}</text>
			</view>
			<view class="row">
				<view class="item" v-for="(item, rowIndex) in array" :key="rowIndex" @click="rowitem(item)">{{ item }}
				</view>
			</view>
			<view class="content-fuzhi" @click="fuzhi">
				<text>{{$t('zhujici.zhujici3')}}</text>
			</view>
		</view>

		<view class="contenter1">
			<text>{{$t('zhujici.zhujici4')}}:</text>
			<text>1.{{$t('zhujici.zhujici5')}}</text>
			<text>2.{{$t('zhujici.zhujici6')}}</text>
			<text>3.{{$t('zhujici.zhujici7')}}</text>
			<text>4.{{$t('zhujici.zhujici8')}}</text>
		</view>

		<view class="anniu" @click="goyanzeng">
			<text>{{$t('zhujici.zhujici9')}}</text>
		</view>
	</view>

</template>

<script>
	import {
		Debounce
	} from "@/api/debounce.js"; //防抖
	export default {
		data() {
			return {
				arrlist: ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
					"red", "green", "yellow", "blue", "black", "white", "orange", "cat", "dog", "pig",
					"bird", "fish", "bear", "panda", "book", "pen", "pencil", "ruler", "bag", "eraser",
					"cup", "run", "jump", "sing", "read", "play", "eat", "sleep", "apple", "banana",
					"cherry", "date", "elephant", "grape", "honey", "ice", "jungle", "kite", "lemon", "river"
				],
				// 假设这是我们的初始数组，长度为 12
				array: []
			};
		},
		onLoad() {
			uni.setNavigationBarTitle({
			  title:  this.$t('phere'), // 必填，页面标题）
			 })
			// 页面加载时调用 randomizeArray 方法
			this.randomizeArray();
		},
		methods: {
			// 随机选择12个单词并添加到array中
			randomizeArray() {
				while (this.array.length < 12) {
					const randomIndex = Math.floor(Math.random() * this.arrlist.length);
					const randomWord = this.arrlist[randomIndex];

					// 确保每个单词只出现一次
					if (!this.array.includes(randomWord)) {
						this.array.push(randomWord);
					}
				}
				
			},
			rowitem(item) {
				console.log('打印内容', item);
			},
			// 复制助记词
			fuzhi(){
				var that = this
				uni.setClipboardData({
					data: String(that.array),
					success: function() {
						that.$modal.msg(that.$t('msg.error6'))
					},
					fail: function(err) {
						// console.log('复制失败:', err);
					}
				});
			},
			goyanzeng: Debounce(function() {
				uni.setStorageSync('phrase',this.array)
				this.$tab.redirectTo('/pages/my/bendiyanzeng')
				
			}, 1000)
		},
	};
</script>

<style scoped>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		color: #000;
	}

	.contenter {
		width: 84%;
		padding: 20px;
		border-radius: 20rpx;
		background-color: #f0f0f0;
	}

	.contenter1 {
		width: 84%;
		padding: 20px;
		border-radius: 20rpx;
		background-color: #f0f0f0;
		display: flex;
		flex-direction: column;
		margin-top: 40rpx;
	}

	.content {
		width: 90%;
		padding: 10px;
		background-color: #f0f0f0;
		border-radius: 20rpx;
		margin-top: 20px;
	}

	.content-title {
		margin-top: 15rpx;
		margin-bottom: 15rpx;

	}

	.content-fuzhi {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #55aaff;
	}

	.row {
		width: 100%;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		margin-bottom: 10px;
	}

	.item {
		width: 21%;
		height: 60rpx;
		/* 每个项目占容器的 30% 宽度，确保一行有 3 个 */
		text-align: center;
		padding: 10px;
		margin: 20rpx;
		background-color: #f0f0f0;
		border-radius: 5px;
		box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
	}

	.anniu {
		width: 90%;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #55aaff;
		color: #fff;
		margin-top: 40rpx;
		border-radius: 20rpx;
	}

	.anniu:active {
		border: 1rpx solid #55aaff;
		background-color: #fff;
		color: #55aaff;
	}
</style>